package com.zengqingfa.algorithm;

/**
 *
 * @fileName: PrintUtil
 * @author: zengqf3
 * @date: 2021-4-5 21:25
 * @description:
 */
public class PrintUtil {

    /**
     * 打印数组中的元素
     * @param arr
     */
    public static void print(int[] arr) {
        if (arr.length == 0) {
            return;
        }
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i]);
                System.out.print(",");
            }
        }
    }

    /**
     * 交换数组中的元素
     * @param arr  数组
     * @param i 索引i
     * @param j 索引j
     */
    public static void swap(int[] arr, int i, int j) {
        //交换位置
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1, 3, 5};
        print(arr);
    }
}
